<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('新增字段检核规则')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-rule-add">			 
            <div class="form-group">
                 <label class="col-sm-3 control-label is-required">系统代码：</label>
                 <div class="col-sm-8">
                     <div class="input-group">
                         <input type="hidden" id="sysId" name="sysId" />
                     	 <input name="sysCode" onclick="selectMdSysModel()" required id="sysCode" type="text" placeholder="请选择系统" autocomplete="off" class="form-control">
                         <span class="input-group-addon"><i class="fa fa-search"></i></span>
                     </div>
                 </div>
             </div>
			<div class="form-group">
				<label class="col-sm-3 control-label">系统名称：</label>
				<div class="col-sm-8">
					<input id="sysName" name="sysName" required class="form-control" readonly="true" type="text"/>
				</div>
			</div>
            <div class="form-group">
                 <label class="col-sm-3 control-label is-required">模块代码：</label>
                 <div class="col-sm-8">
                     <div class="input-group">
                         <input type="hidden" id="moduleId" name="moduleId" />
                     	 <input name="moduleCode" required onclick="selectMdModule()" autocomplete="off" id="moduleCode" type="text" placeholder="请选择功能模块" class="form-control">
                         <span class="input-group-addon"><i class="fa fa-search"></i></span>
                     </div>
                 </div>
             </div>
			<div class="form-group">
				<label class="col-sm-3 control-label">模块名称：</label>
				<div class="col-sm-8">
					<input id="moduleName" name="moduleName" required class="form-control" readonly="true" type="text"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">表代码：</label>
				<div class="col-sm-8">
					<div class="input-group">
					    <input type="hidden" id="tableId" name="tableId" />
                     	<input name="tableCode" onclick="selectMdTable()" autocomplete="off" required id="tableCode" type="text" placeholder="请选择表代码" class="form-control">
                         <span class="input-group-addon"><i class="fa fa-search"></i></span>
                     </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">表名称：</label>
				<div class="col-sm-8">
					<input id="tableName" name="tableName" required class="form-control" readonly="true" type="text"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">字段代码：</label>
				<div class="col-sm-8">
					<div class="input-group">
                     	<input name="fieldCode" required onclick="selectFieldCodeTable()" autocomplete="off" id="fieldCode" type="text" placeholder="请选择表代码" class="form-control">
                         <span class="input-group-addon"><i class="fa fa-search"></i></span>
                     </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">字段名称：</label>
				<div class="col-sm-8">
					<input id="fieldName" name="fieldName" class="form-control" readonly="true" type="text"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">字段说明：</label>
				<div class="col-sm-8">
					<input name="fieldRemark" class="form-control" type="text" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">字段类型：</label>
				<div class="col-sm-8">
					<input name="fieldType" id="fieldType" class="form-control" type="text" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">规则类型</label>
				<div class="col-sm-8">
					<select name="ruleType" required class="form-control m-b"
						th:with="type=${@dict.getType('rule_type')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
							th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">规则：</label>
				<div class="col-sm-8">
					<input name="rule" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">规则说明：</label>
				<div class="col-sm-8">
					<textarea name="ruleRemark" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "verify/rule"
		$("#form-rule-add").validate({
			focusCleanup : true
		});

		function submitHandler() {debugger;
			if ($.validate.form()) {
				var data = $("#form-rule-add").serializeArray();
	        	//var sysId = $("#sysId").val();
	        	//data.push({"name": "sysId", "value": sysId});
	        	//$.operate.saveTab(prefix + "/add", data);
				$.operate.save(prefix + "/add", data);
			}
		}
		/* 选择系统 */
        function selectMdSysModel() {debugger;
        	var url = prefix + "/showMdSysList";
			var options = {
				title: '选择系统',
				width: "600",
				url: url,
				callBack: doSubmitMdSysData
			};
			$.modal.openOptions(options);
		}
        function doSubmitMdSysData(index, layero){debugger;
	       var tableObj = layero.find("iframe")[0].contentWindow.$.table;
	       var sysId = tableObj.selectColumns("sysId")[0];
	       var sysCode = tableObj.selectColumns("sysCode")[0];
	       var sysName = tableObj.selectColumns("sysName")[0];
	        $("#sysId").val(sysId);
			$("#sysCode").val(sysCode);
			$("#sysName").val(sysName);
			layer.close(index);
	    }
     
		/* 选择功能模块 */
        function selectMdModule() {debugger;
        	var sysId = $("#sysId").val();
        	if($.validate.isEmpty(sysId)){
        		$.modal.alertError("系统代码不能为空!");
        		return;
        	}
        	var url = prefix + "/showMdModuleList/" + sysId;
			var options = {
				title: '选择功能模块',
				width: "600",
				url: url,
				callBack: doSubmitSelectModelData
			};
			$.modal.openOptions(options);
		}
		//选择表代码  
        function selectMdTable() {debugger;
	    	var moduleId = $("#moduleId").val();
	    	if($.validate.isEmpty(moduleId)){
        		$.modal.alertError("模块代码不能为空!");
        		return;
        	}
	    	var url = prefix + "/showMdTableList/" + moduleId;
			var options = {
				title: '选择表模块',
				width: "600",
				url: url,
				callBack: doSubmitSelectTableModeData
			};
			$.modal.openOptions(options);
		}
      //选择字段代码 
        function selectFieldCodeTable() {
			var tableId = $("#tableId").val();
			if($.validate.isEmpty(tableId)){
        		$.modal.alertError("表代码不能为空!");
        		return;
        	}
	    	var url = prefix + "/showMdFieldList/" + tableId;
	    	var options = {
					title: '选择字段',
					width: "600",
					url: url,
					callBack: doSubmitSelectMdFieldData
				};
				$.modal.openOptions(options);
		}  
        
        function doSubmitMdSysData(index, layero){debugger;
	       var tableObj = layero.find("iframe")[0].contentWindow.$.table;
	       var sysId = tableObj.selectColumns("sysId")[0];
	       var sysCode = tableObj.selectColumns("sysCode")[0];
	       var sysName = tableObj.selectColumns("sysName")[0];
	        $("#sysId").val(sysId);
			$("#sysCode").val(sysCode);
			$("#sysName").val(sysName);
			layer.close(index);
	    }
        
		function doSubmitSelectModelData(index, layero){debugger;
		     var tableObj = layero.find("iframe")[0].contentWindow.$.table;
		     var moduleId = tableObj.selectColumns("moduleId")[0];
		     var moduleCode = tableObj.selectColumns("moduleCode")[0];
		     var moduleName = tableObj.selectColumns("moduleName")[0];
		     $("#moduleId").val(moduleId);
   			$("#moduleCode").val(moduleCode);
   			$("#moduleName").val(moduleName);
   			layer.close(index);
		}
		function doSubmitSelectTableModeData(index, layero){debugger;
		     var tableObj = layero.find("iframe")[0].contentWindow.$.table;
		     var tableId = tableObj.selectColumns("tableId")[0];
		     var tableCode = tableObj.selectColumns("tableCode")[0];
		     var tableName = tableObj.selectColumns("tableName")[0];
		     $("#tableId").val(tableId);
			$("#tableCode").val(tableCode);
			$("#tableName").val(tableName);
			layer.close(index);
	     }
		function doSubmitSelectMdFieldData(index, layero){debugger;
		     var tableObj = layero.find("iframe")[0].contentWindow.$.table;
		     var fieldCode = tableObj.selectColumns("fieldCode")[0];
		     var fieldName = tableObj.selectColumns("fieldName")[0];
				$("#fieldCode").val(fieldCode);
				$("#fieldName").val(fieldName);
				layer.close(index);
	    }
		/* 系统代码列表*/
		function selectsysCodeList() {
			debugger;
			var url = ctx + "verify/rule/systemListData";
			showsysCodeDialog(url);
		}

		function showsysCodeDialog(url) {
			var box = '<div id="mytable" style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;"><table></table></div>';
			var table2 = '<div class="col-sm-12 select-table table-striped"><table id="table2"></table></div>';
			var options = {
				url : prefix + "/list",
				createUrl : prefix + "/add",
				updateUrl : prefix + "/edit/{id}",
				removeUrl : prefix + "/remove",
				exportUrl : prefix + "/export",
				modalName : "字段检核规则",
				columns : [ {
					checkbox : true
				}, {
					field : 'checkRuleId',
					title : '检核规则id',
					visible : false
				}, {
					field : 'sysCode',
					title : '系统代码'
				}, {
					field : 'systemName',
					title : '系统名称'
				} ]
			};
			layer.open({
				type : 1,
				title : false, //不显示标题栏
				closeBtn : false,
				area : '500px;',
				shade : 0.8,
				id : 'LAY_layuipro', //设定一个id，防止重复弹出
				btn : [ '确认', '取消' ],
				btnAlign : 'c',
				moveType : 1, //拖拽模式，0或者1
				content : table2,
				success : function(layero) {
					$.table.init2(options, "table2");
				}
			});
		}
	</script>
</body>
</html>
